package org.bonorsoft.modules.system.framework.web.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.bonorsoft.common.util.oConvertUtils;
import org.bonorsoft.modules.dingding.entity.SysDepart;
import org.bonorsoft.modules.dingding.entity.SysDingUser;
import org.bonorsoft.modules.dingding.service.ISysDepartService;
import org.bonorsoft.modules.dingding.service.ISysDingUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("dingUser")
public class DingUserService {
    @Autowired
    private ISysDingUserService dingUserService;

    @Autowired
    private ISysDepartService departService;

    /**
     * 根据发件人id获取发件人姓名
     *
     * @param value
     * @return
     */
    public String getNoticeSenderValue(String value) {

        String name = "-";
        if (oConvertUtils.isNotEmpty(value)) {
            try {
                SysDingUser user = dingUserService.getById(value);
                name = user.getName();
            }catch (Exception e){
                try {
                    SysDepart depart = departService.getById(value);
                    name = depart.getName();
                }catch (Exception ex){
                    name = value;
                }
            }
        }
        return name;
    }

    public String getAddresseeNameValue(String value) {

        String name = "-";
        if (oConvertUtils.isNotEmpty(value)) {
            try {
                SysDingUser user = dingUserService.getUserByMobile(value);
                name = user.getName();
            }catch (Exception e){
                try {
                    SysDepart depart = departService.getById(value);
                    name = depart.getName();
                }catch (Exception ex){
                    name = value;
                }
            }
        }
        return name;
    }
}
